import { View, Swiper, SwiperItem, Image } from '@tarojs/components';
import Taro from '@tarojs/taro';
import { checkAuth } from '@/utils/authUtil';
import { sendClickData } from '@/service/apis/home/index';
import globalStore from '@/store/global';
import { BannerJumpType } from '../../constants';
import './index.scss';

export default function ({ bannerList }) {
  const onJump = (banner) => {
    console.log('banner', banner);
    if (banner.type_value === '空') return;
    sendClickData({
      ad_id: banner.id,
    });
    switch (banner.type) {
      // 商品
      case BannerJumpType.Product: {
        Taro.navigateTo({
          // url: `/pages/goods/detail/index?id=${banner.type_balue}`,
          url: `/pages/contrast/detail/index?goods_sn=${banner.type_value}&lat=${globalStore.currentShop.lat}&lng=${globalStore.currentShop.lng}&type=product`,
        });
        break;
      }
      // 服务
      case BannerJumpType.Service: {
        Taro.navigateTo({
          // url: `/pages/appointment/detail/index?id=${banner.type_balue}`,
          url: `/pages/contrast/detail/index?goods_sn=${banner.type_value}&lat=${globalStore.currentShop.lat}&lng=${globalStore.currentShop.lng}&type=service`,
        });
        break;
      }
      // 活动
      case BannerJumpType.Activity: {
        checkAuth(() => {
          Taro.navigateTo({
            url: `/subPages/myActivity/detail/index?topic_id=${banner.type_value}`,
          });
        });
        break;
      }
      // 外链
      case BannerJumpType.Url: {
        Taro.navigateTo({
          url: `/pages/webview/index?url=${banner.type_value}`,
        });
        break;
      }
      // 购买会员
      case BannerJumpType.Vip: {
        Taro.navigateTo({
          url: `/subPages/vipCardDetail/index`,
        });
        break;
      }
    }
  };
  return (
    <View className="home-banner">
      <Swiper
        className="banner-swiper"
        indicatorColor="#999"
        indicatorActiveColor="#333"
        indicatorDots
        circular
        autoplay
        interval={3000}
      >
        {bannerList.map((item) => {
          return (
            <SwiperItem key={item.id}>
              <View className="swiper-item" onClick={() => onJump(item)}>
                <Image src={item.url} mode="aspectFill" />
              </View>
            </SwiperItem>
          );
        })}
      </Swiper>
    </View>
  );
}
